<form name="balanceEditForm" class="form-horizontal" novalidate>
    <div data-ng-controller="contractBalanceCtrl">
        <div class="table-header clearfix ng-scope">
            <span class="fl lh30 f14">{{contractBaseInfo.contract_code}}</span>

            <div class="ml35 fr">
                <button type="submit" ng-if="userAuthList.indexOf('0001') !== -1" ng-click="balanceEditForm.$valid && save()" class="btn btn-default">保存
            </button>
            </div>

        </div>
        <div class="mt20 ml25 clearfix" ng-if="!areaRole">
            <div>
                <div id="fileupload" class="fileinput-button btn" ng-show="userAuthList.indexOf('0001') !== -1">
                    <span class="f13">上传附件</span>
                    <input type="file" name="file" accept=".xls,.xlsx,.doc,.docx,.pdf,.msg">
                </div>
                <div class="c-red f13" style="clear:both;display: none;" id="fileupload_tip">上传中……</div>
                <div class="c-red f13" style="clear:both;display: none" id="fileupload_error">上传失败</div>
                <input type="hidden" id="fileupload_url" value="{{contractFiles}}" />

                <div>
                    <div style="height: 28px;display: inline-block;margin-right: 20px" ng-repeat="file in contractFiles" ng-if="file.__type != 'delete'">
                        <a target="_blank" href="{{file.attachement_path}}">{{file.attachement_name}}</a>
                        <a class="glyphicon glyphicon-trash" title="删除附件" href="javascript: void(0)" ng-click="delAttachment(file,$index)"></a>
                    </div>
                </div>

            </div>
        </div>

        <div class="form-group mt10">
            <span class="col-sm-3 control-label">合同产品标准金额</span>

            <div class="col-sm-5">
                <input type="text" ng-model="balanceInfo.application_amount" class="form-control align-r" ng-disabled="true" placeholder="合同产品标准金额">
            </div>
            <span class="col-sm-3 control-label">合同成交总额</span>

            <div class="col-sm-5">
                <input type="text" ng-model="balanceInfo.sign_amount" class="form-control align-r" ng-disabled="true" placeholder="合同产品成交总额">
            </div>
            <span class="col-sm-3 control-label">项目数</span>

            <div class="col-sm-5">
                <input type="text" ng-model="balanceInfo.project_numeric" class="form-control align-r" placeholder="项目数">
            </div>
        </div>

        <div class="form-group mt10">
            <span class="col-sm-3 control-label">已结算金额合计</span>

            <div class="col-sm-5">
                <input type="number" ng-model="balanceInfo.balance_amount" ng-if="!isSpecialContract" class="form-control align-r" placeholder="已结算金额"
                    required min="0" number name="balance_amount" />
                <input type="number" ng-if="isSpecialContract" disabled class="form-control align-r" placeholder="已结算金额" ng-value="projects|sumSettlementAverageAmount2:'settlement_average_amount'"
                />
                <span role="alert" ng-show="(balanceEditForm.$submitted || balanceEditForm.balance_amount.$touched) && balanceEditForm.balance_amount.$error.required"
                    class="error ng-hide c-red lh30">已结算金额不能为空</span>
                <span role="alert" ng-show="(balanceEditForm.$submitted || balanceEditForm.balance_amount.$touched) && balanceEditForm.balance_amount.$error.number"
                    class="error ng-hide c-red lh30">已结算金额必须是数值类型</span>
                <span role="alert" ng-show="(balanceEditForm.$submitted || balanceEditForm.balance_amount.$touched) && (balanceEditForm.balance_amount.$error.min)"
                    class="error ng-hide c-red lh30">已结算金额必须大于等于0</span>
                <span role="alert" ng-show="(balanceEditForm.$submitted || balanceEditForm.balance_amount.$touched) && (balanceEditForm.balance_amount.$error.max)"
                    class="error ng-hide c-red lh30">已结算金额不能超过基本信息的收入金额 {{contractBaseInfo.income_amount}}</span>
            </div>

            <span ng-if="!isSpecialContract" class="col-sm-3 control-label">返款金额</span>

            <div ng-if="!isSpecialContract" class="col-sm-5">
                <input type="number" ng-model="balanceInfo.back_amount" ng-disabled="true" class="form-control align-r" placeholder="自动计算"
                    required min="0" number name="back_amount">
                <!--<span role="alert"-->
                <!--ng-show="(balanceEditForm.$submitted || balanceEditForm.back_amount.$touched) && balanceEditForm.back_amount.$error.required"-->
                <!--class="error ng-hide c-red lh30">返款金额不能为空</span>-->
                <!--<span role="alert"-->
                <!--ng-show="(balanceEditForm.$submitted || balanceEditForm.back_amount.$touched) && balanceEditForm.back_amount.$error.number"-->
                <!--class="error ng-hide c-red lh30">返款金额必须是数值类型</span>-->
                <!--<span role="alert"-->
                <!--ng-show="(balanceEditForm.$submitted || balanceEditForm.back_amount.$touched) && (balanceEditForm.back_amount.$error.min)"-->
                <!--class="error ng-hide c-red lh30">返款金额必须大于等于0</span>-->
            </div>


            <span ng-if="(isDefined || 0) != 0" class="col-sm-3 control-label">返款时间</span>
            <div ng-if="(isDefined || 0) != 0" class="col-sm-5">
                <input type="text" class="input-date fl form-control" style="width:100%" ui-date format="yyyy-MM-dd" name="repayment_time"
                    ng-model="balanceInfo.repayment_time" placeholder="返款时间">
                <span role="alert" ng-show="(balanceEditForm.$submitted || balanceEditForm.sign_date.$touched) && balanceEditForm.repayment_time.$error.required"
                    class="error ng-hide c-red lh30">返款时间不能为空</span>
            </div>
        </div>

        <div ng-if="(isDefined || 0) != 0" class="form-group mt10">
            <span ng-if="(isDefined || 0) != 0" class="col-sm-3 control-label">返款类型</span>
            <div ng-if="(isDefined || 0) != 0" class="col-sm-5">
                <input select2 ng-model="balanceInfo.repayment_type" select2-model="ddl2RepaymentType" config="ddlConfigRepaymentType" class="form-control"
                    type="text" required name="repayment_type" />
                <span role="alert" ng-show="(balanceEditForm.$submitted || balanceEditForm.repayment_type.$touched) && balanceEditForm.repayment_type.$error.required"
                    class="error ng-hide c-red lh30">返款类型不能为空</span>
            </div>

            <span for="idBalanceStatus" class="col-sm-3 control-label">是否返款</span>
            <div class="col-sm-5">
                <input id="idBalanceStatus" name="balance_status" select2 required ng-model="balanceInfo.balance_status" select2-model="ddl2BalanceStatus"
                    config="ddlConfigBalanceStatus" class="form-control" type="text" />
                <span role="alert" ng-show="(contractBaseForm.$submitted || contractBaseForm.balance_status.$touched) && contractBaseForm.balance_status.$error.required"
                    class="error ng-hide c-red lh30">是否返款不能为空</span>
            </div>

        </div>
        <div ng-if="(isDefined || 0) != 0" class="form-group mt10">
            <span for="idRepaymentCompany" class="col-sm-3 control-label">服务机构</span>
            <div class="col-sm-7">
                <input id="idRepaymentCompany" name="repayment_company" select2 required ng-model="balanceInfo.repayment_company" select2-model="ddl2RepaymentCompany"
                    config="ddlRepaymentCompany" class="form-control" type="text" />
                <span role="alert" ng-show="balanceEditForm.$submitted && balanceEditForm.repayment_company.$error.required" class="error ng-hide c-red lh30">服务机构不能为空</span>
            </div>


        </div>

        <div class="form-group mt10">
            <span class="col-sm-3 control-label">备注</span>

            <div class="col-sm-21">
                <textarea type="text" ng-model="balanceInfo.balance_remark" class="form-control" placeholder="备注" rows="4"></textarea>
            </div>
        </div>

        <!--新增产品-->
        <div>
            ${require('./balance-inc-projects.html')}
        </div>

        <div class="mt20 clearfix" style="text-align: right;">
            <button class="btn" ng-if="userAuthList.indexOf('0001') !== -1" ng-hide="isEditMode" ng-click="toggleEdit()">编辑
            </button>
            <button type="submit" class="btn" ng-if="userAuthList.indexOf('0001') !== -1" ng-show="isEditMode" ng-click="validEq() && saveCategores()">保存
            </button>
        </div>
        <!-- 签约分摊金额、结算分摊金额、回款分摊金额列表 -->
        <div>
            ${require('../../editinc/balance-inc-distribution-amount.html')}
        </div>
    </div>
</form>